The Companion Tab Navigation controller (attached to the Gameboard prefab game object) exposes all the tab navigation options available to creators. This controller allows you to show a tabbed navigation within companion to swap between hands and optionally the dice view. You can also listen to tab navigation pressed events, so the game can keep track of what hadn the user is on.

Tab Navigation with 2 hands (both labeled CardList)

Step-by-Step

Tab Navigation view from Dice

Step-by-Step

Tab Navigation view with more than 3 tabs

Step-by-StepStep-by-Step

The Gameboard prefab is always available in your game as long as the SDK has been integrated. In order to access it from our custom Mono Behavior we just need to find it by its tag.

    GameObject gameboardObject = GameObject.FindWithTag("Gameboard");

With access to our Gameboard object we can then move on to optain a reference to the Companion Tab Navigation controller. This is the controller that handles all the functions related to companion tab navigation.

We will first need to define a reference to the controller to make it available throughout our script.

     CompanionTabNavController tabNavController;

We then want to define the controller by getting it from the gameboardObject and we also want to define our listener. We can now proceed to listen for tab navigation press events. In our case well have a function called OnCompanionTabNavPressed handle these events.

    tabNavController = gameboardObject.GetComponent<CompanionTabNavController>();
    tabNavController.CompanionTabNavPressed += OnCompanionTabNavPressed;

With the controller at hand we can now show the tab navigation on companion. Send the userId of the user's companion that you would like to show the tab navigation of and a TabNavigationOptions object with the properties as you would like them.

Property Descriptions

    // Set the default tab view with the dice screen as a tab
    CompanionMessageResponseArgs response = await tabNavController.ShowTabNavigation(userId, new TabNavigationOptions()
    {
        display = true,
        includeDiceScreen = true,
    });

To hide the tab navigation, just pass display = false

    CompanionMessageResponseArgs response = await tabNavController.ShowTabNavigation(userId, new TabNavigationOptions()
    {
        display = false
    });

Now that we are able to receive the tab navigation pressed events, all that remains is to handle them in the game.

    void OnCompanionTabNavPressed(GameboardTabNavPressedEventArgs companionTabEvent)
    {
        // Navigation pressed event
        // The companionTabEvent includes the handId the user is now viewing, or a flag saying if they switched to the dice view
    }

Although we are working in a managed environment, it is always a good idea to clean the listeners when no longer needed.

    void OnDestroy()
    {
        tabNavController.CompanionTabNavPressed -= OnCompanionTabNavPressed;
    }

This section include the entire code in one single, easy to copy section.

    CompanionTabNavController tabNavController;

    // Start is called before the first frame update
    void Start()
    {
        GameObject gameboardObject = GameObject.FindWithTag("Gameboard");
        tabNavController = gameboardObject.GetComponent<CompanionTabNavController>();
        tabNavController.CompanionTabNavPressed += OnCompanionTabNavPressed;
    }

    void OnCompanionTabNavPressed(GameboardTabNavPressedEventArgs companionTabEvent)
    {
        // Navigation pressed event
        // The companionTabEvent includes the handId the user is now viewing, or a flag saying if they switched to the dice view
    }

    async void ShowTabs(string userId)
    {
        CompanionMessageResponseArgs response = await tabNavController.ShowTabNavigation(userId, new TabNavigationOptions()
        {
            display = true,
            includeDiceScreen = true,
        });
    }

    async void HideTabs(string userId)
    {
        CompanionMessageResponseArgs response = await tabNavController.ShowTabNavigation(userId, new TabNavigationOptions()
        {
            display = false
        });
    }

    void OnDestroy()
    {
        tabNavController.CompanionTabNavPressed -= OnCompanionTabNavPressed;
    }